/*
 * SubmitCharacterWindow.java
 *
 * Created on September 5, 2008, 4:27 PM
 */
package com.lct.eq2.gui;

import java.awt.Toolkit;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import javax.swing.JOptionPane;

/**
 *
 * @author  waite
 */
public class SubmitCharacterWindow extends javax.swing.JFrame {

    private String characterName;
    private String serverName;

    public static void main(String[] args) {
        SubmitCharacterWindow submit = new SubmitCharacterWindow("Shinzul", "Todbringer");
        submit.setVisible(true);
    }

    /** Creates new form SubmitCharacterWindow */
    public SubmitCharacterWindow(String characterName, String serverName) {
        this.characterName = characterName;
        this.serverName = serverName;
        initComponents();
        this.setIconImage(Toolkit.getDefaultToolkit().getImage("WAR.gif"));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Submit");

        jButton1.setText("Submit");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel1.setText("http://warct.com username:");

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 136, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jTextField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jButton1))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jLabel1)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jButton1)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    System.setProperty("java.net.useSystemProxies", "true");
    String surl = "http://warcombattracker.ath.cx:8080/validate.jsp?character=" + characterName.replaceAll(" ", "+") + "&servername=" + this.serverName.replaceAll(" ", "+") + "&username=" + this.jTextField1.getText().replaceAll(" ", "+");
    BufferedReader br = null;
    try {
        URL url = new URL(surl);
        br = new BufferedReader(new InputStreamReader(url.openStream()));
    } catch (MalformedURLException ex) {
        //ex.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        try {
            br.close();
        } catch (IOException ex) {
            //ex.printStackTrace();
        }
    }
    JOptionPane.showMessageDialog(null, "You have successfully submitted " + this.characterName + " for verification. " +
            "Visit your account page at http://warcombattracker.com to finish.", "Submitted", JOptionPane.INFORMATION_MESSAGE);
    this.setVisible(false);
    this.dispose();
}//GEN-LAST:event_jButton1ActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
}
